package com.jiepos.mpos.biz.appInfM.service;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jiepos.mpos.common.constant.SystemConstant;
import com.jiepos.mpos.common.dao.CustomMsgDao;
import com.jiepos.mpos.common.entity.App_Custom_MsgEntity;
import com.jiepos.mpos.core.service.BaseService;
import com.jiepos.mpos.core.util.IDFactoryUtil;

/**
 * 消息阅读状态Service
 * @author Zhao.Jinkui
 * @version 1.0
 * @ProjectName: mpos
 * @Package com.jiepos.mpos.biz.appInfM.service
 * @ClassName CustomMsgService
 * @history
 * @UpdateRemark []
 * @since 2017/10/25
 */
@Service
public class CustomMsgService extends BaseService {
    @Autowired
    private CustomMsgDao customMsgDao;

    /**
     * 增加消息已读记录
     * @param custom_uuid
     * @param message_uuid
     */
    public void saveMsgStatus(String custom_uuid,String message_uuid){
        App_Custom_MsgEntity entity = new App_Custom_MsgEntity();
        entity.setCustom_msg_uuid(IDFactoryUtil.getUUID());
        entity.setCustom_uuid(custom_uuid);
        entity.setMessage_uuid(message_uuid);
        entity.setRead_st(SystemConstant.READ_ST_1);//已读
        entity.setRec_upd_ts(new Timestamp(System.currentTimeMillis()));
        customMsgDao.save(entity);
    }

    /**
     * 批量增加已读记录
     * @param custom_uuid
     * @param message_uuids
     */
    public void saveBatchMsgStatus(String custom_uuid,List<String> message_uuids){
        StringBuffer sqlBuf = new StringBuffer("INSERT ALL ");
        for (String uuid : message_uuids){
            sqlBuf.append("INTO T_APP_CUSTOM_MSG (CUSTOM_MSG_UUID,CUSTOM_UUID,MESSAGE_UUID,READ_ST,REC_UPD_TS) VALUES ('");
            sqlBuf.append(IDFactoryUtil.getUUID());
            sqlBuf.append("','");
            sqlBuf.append(custom_uuid);
            sqlBuf.append("','");
            sqlBuf.append(uuid);
            sqlBuf.append("','");
            sqlBuf.append(SystemConstant.READ_ST_1);
            sqlBuf.append("',SYSTIMESTAMP) ");
        }
        sqlBuf.append("SELECT 1 FROM DUAL");
        customMsgDao.update(sqlBuf.toString());
    }
}
